home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
escalant
/
escala21.lha
/
escalante2.1
/
src
/
editor
/
Escalante.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-15
|
18KB
|
823 lines
//
// Copyright (C) 1993 Jeff McWhirter
//
//$EscalanteDocument$
#include "Escalante.h"
#include "ET++.h"
#include "Env.h"
#include "LineItem.h"
#include "Filler.h"
#include "MenuBar.h"
#include "ObjArray.h"
#include "ObjList.h"
#include "CollView.h"
#include "FileDialog.h"
#include "CollView.h"
#include "Look.h"
#include "Scroller.h"
#include "Clipper.h"
#include "WindowSystem.h"
#include "Token.h"
#include "WindowPort.h"
#include "Buttons.h"
#include "Scroller.h"
#include "Zoomer.h"
#include "PrintManager.h"
#include "Form.h"
#include "BorderItems.h"
#include "CommandProcessor.h"
#include "SizeableExp.h"
#include "VObjGfx.h"
#include "EscalanteView.h"
int gPaletteDocumentRows;
int gPaletteDocumentCols;
bool gPaletteDocumentSquare;
char * cDocTypeBasic= "ESCALANTE";
char * cDocTypeSgVgs = "SGVGS";
char * cDocTypeSgVg = "SGVG";
char * cDocTypeVg = "VG";
char * cDocTypeVgs = "VGS";
float gObsViewZoom = 0.40;
EscalanteManager * gEscalanteManager =0;
//---- EscalanteDocument ----------------------------------------------------------
NewMetaImpl(EscalanteDocument,Document, (TP(vgraph), TP(views),0));
EscalanteDocument::~EscalanteDocument(){
if(views)
views->FreeAll();
SafeDelete(views);
}
bool EscalanteDocument::Close(){
bool result = Manager::Close();
if(views && result){
BaseEscalanteView * v;
Iter next(views);
while(v = (BaseEscalanteView*)next())
v->Send(cViewClosed,0,(void*)v);
}
return result;
/**
bool result = EscalanteDocument_BASE::Close();
if(views && result){
BaseEscalanteView * v;
Iter next(views);
while(v = (BaseEscalanteView*)next())
v->NewGraph(0,0,FALSE);
}
return result;
**/
}
void EscalanteDocument::MyClose(){
if(views){
BaseEscalanteView * v;
Iter next(views);
while(v = (BaseEscalanteView*)next())
v->NewGraph(0,FALSE);
}
}
EscalanteDocument::EscalanteDocument(VGraphElement * ve) : Document(cDocTypeBasic){
vgraph = ve;
views = new ObjList();
SetOnDismiss(eMgrClose);
}
void EscalanteDocument::DoSetupMenu(Menu* m ){
register EscalanteView * dv;
Iter next(views);
int id = m->GetId();
if(id == cALLDV ||
id == cDVMENU ||
id == cDELMENU||
id == cPICKMENU ||
id == cESCALANTE_EDITMENU ){
while(dv = (EscalanteView*)next())
if( dv != gFirstHandler)
dv->DoSetupMenu(m);
}
m->EnableItem(cQUIT);
Document::DoSetupMenu(m);
}
MenuBar *EscalanteDocument::DoMakeMenuBar()
{
if(!Env::GetValue("EscalanteDocument.MakeMenuBar",1))
return 0;
MenuBar *mb= new MenuBar();
if(Env::GetValue("EscalanteDocument.MakeHelpMenu",1))
mb->AddMenu(MakeMenu(cHELPMENU));
if(Env::GetValue("EscalanteDocument.MakeFileMenu",1))
mb->AddMenu(MakeMenu(cFILEMENU));
Menu * helpm = mb->FindMenu(cHELPMENU);
if(helpm){
helpm->RemoveItem(cHELP);
helpm->AppendItem("About View",ABOUTVIEW);
helpm->AppendItem("About Current Mode",ABOUTCURRENTMODE);
helpm->AppendItem("About A Mode",ABOUTMODE);
helpm->AppendItem("About Element",ABOUTELT);
helpm->AppendItem("Misc.", ABOUTMISC);
}
Menu * filem = mb->FindMenu(cFILEMENU);
if(filem){
filem->RemoveItem(cNEW);
filem->RemoveItem(cOPEN);
filem->RemoveItem(cREVERT);
}
Menu * m;
if(Env::GetValue("EscalanteDocument.MakeViewMenu",1)){
m = EscalanteView::MakeMenu(cALLDV);
if(m){
m->SetName("View");
mb->AddMenu(m);
}
}
if(Env::GetValue("EscalanteDocument.MakeDeleteMenu",1) && ! gDeleteInEdit){
m = EscalanteView::MakeMenu(cDELMENU);
if(m){
m->SetName("Delete");
mb->AddMenu(m);
}
}
if(Env::GetValue("EscalanteDocument.MakePickMenu",1) && ! gPickInEdit){
m = EscalanteView::MakeMenu(cPICKMENU);
if(m){
m->SetName("Pick");
mb->AddMenu(m);
}
}
if(Env::GetValue("EscalanteDocument.MakeEditMenu",1)){
m = EscalanteView::MakeMenu(cESCALANTE_EDITMENU);
if(m){
m->SetName("Edit");
mb->AddMenu(m);
}
}
return mb;
}
EscalanteView * EscalanteDocument::MakeEscalanteView(int id,Point p, VGraphElement *vg){
return new EscalanteView(id,this,p,vg);
}
VObject *EscalanteDocument::DoMakeContent(){
if(!vgraph)return 0;
EscalanteView * dv=0;
ScaledObserverView * ov=0;
gPickInEdit = Env::GetValue("EscalanteView.PickMenuInEditMenu", 0);
gDeleteInEdit = Env::GetValue("EscalanteView.DeleteMenuInEditMenu", 0);
gDoKeyCommands = Env::GetValue("EscalanteView.DoKeyCommands", 0);
gDoFromTlAttrMap = Env::GetValue("Escalante.DoFromTlAttrMap", 1);
gDoFromHdAttrMap = Env::GetValue("Escalante.DoFromHdAttrMap", 1);
gDoFromRelAttrMap = Env::GetValue("Escalante.DoFromRelAttrMap", 1);
bool makeObserver = Env::GetValue("EscalanteDocument.MakeObserver",FALSE);
bool withPalette = Env::GetValue("EscalanteDocument.MakeObserverWithPalette",FALSE);
bool sepObs = Env::GetValue("EscalanteDocument.MakeSeparateObserver",0);
bool separatePalette = Env::GetValue("EscalanteView.MakeSeparatePalette",FALSE);
cIdEscalanteView += cIdEscalanteViewInc;
dv= MakeEscalanteView(cIdEscalanteView,Point(5000),vgraph);
if(dv){
dv->InitView();
if((separatePalette || dv->MakeSeparatePalette())&&
!dv->DoNotMakeExtraPalette())
gEscalanteManager->AddManager(new PaletteDocument(dv));
gPrintManager->AddObserver(dv);
SetFirstHandler(dv);
AddEscalanteView(dv);
vgraph->AddView(dv);
if(makeObserver && !dv->DoNotMakeObserverView()) {
cIdEscalanteView += cIdEscalanteViewInc;
ov=new ScaledObserverView(dv,cIdEscalanteView,this,Point(2000),vgraph,withPalette);
ov->InitView();
AddEscalanteView(ov);
vgraph->AddView(ov);
}
if(sepObs && !dv->DoNotMakeObserverView())
gEscalanteManager->AddManager(new ObserverDocument(vgraph,dv));
}
VObject * viewVop, * obsVop;
if(dv && ov){
viewVop = dv->GetView();
obsVop = ov->GetView();
ov->InitObserver(gObsViewZoom);
LineItem*line = new LineItem(TRUE,2);
line->SetFlag(eVObjVFixed,TRUE);
line->SetFlag(eVObjHFixed,FALSE);
Filler * filler =new Filler(Point(0,2));
filler->SetFlag(eVObjVFixed,TRUE);
filler->SetFlag(eVObjHFixed,FALSE);
Filler * filler2 =new Filler(Point(0,2));
filler2->SetFlag(eVObjVFixed,TRUE);
filler2->SetFlag(eVObjHFixed,FALSE);
return new Expander(0,eVert,gPoint0,viewVop,filler,line,filler2,obsVop,0);
}
else if(dv) return new Expander(0,eVert,gPoint0,dv->GetView(),0);
return 0;
}
VObject *ObserverDocument::DoMakeContent(){
ScaledObserverView * sov=0;
cIdEscalanteView += cIdEscalanteViewInc;
sov=new ScaledObserverView(theview,cIdEscalanteView,this,Point(2000),vgraph,FALSE);
sov->InitObserver(gObsViewZoom);
sov->InitView();
gPrintManager->AddObserver(sov);
SetFirstHandler(sov);
AddEscalanteView(sov);
vgraph->AddView(sov);
return new Expander(0,eVert,gPoint0,sov->GetView(),0);
}
void EscalanteDocument::Control(int id, int part, void *val)
{
//bool sent = FALSE;
//Iter next(views);
//BaseEscalanteView * v;
//while((v = (BaseEscalanteView*)next()) && !sent)
// sent = v->Interested(id,part,val);
//if(!sent)
Document::Control(id, part, val);
}
Command *EscalanteDocument::DoMenuCommand(int cmd){
//
//Loop through each view in this document and see if it is
//interested in this menu command
//
Iter next(views);
BaseEscalanteView * v;
Command * c;
while((v = (BaseEscalanteView*)next())){
c= v->Interested(cmd);
if(c != gNoChanges)
return c;
}
//
//Catch any save/read/etc commands and pass them along to the
//EscalanteManager to handle
//
switch(cmd) {
case cSAVE:
case cSAVEAS:
case cLOAD:
case cREVERT:
return Manager::DoMenuCommand(cmd);
}
return EscalanteDocument_BASE::DoMenuCommand(cmd);
}
NewMetaImpl(EscalanteManager,EscalanteManager_BASE,(TP(vgraphs),TP(sgraph),0));
EscalanteDocument * EscalanteManager::NewEscalanteDocument(VGraphElement *v){
EscalanteDocument * gd;
if(vgraphs && v && ! vgraphs->Contains(v))
vgraphs->Add(v);
gd = MakeEscalanteDocument(v);
if(gd) AddManager(gd);
return gd;
}
EscalanteDocument * EscalanteManager::MakeEscalanteDocument(VGraphElement *vg){return new EscalanteDocument(vg);}
bool EscalanteManager::Close(){
//Modified(FALSE);
//gGraphModified = FALSE;
if(SavedChanges())
return Manager::Close();
return FALSE;
}
bool EscalanteManager::Modified(){
return ((TestFlag(eEscalanteManModified)||gGraphModified)? TRUE:EscalanteManager_BASE::Modified());
}
VObject *EscalanteManager::DoMakeContent(){
if(!vgraphs)return 0;
Iter next(vgraphs);
VGraphElement * vg;
EscalanteDocument * gd;
while(vg = (VGraphElement*)next()) {
gd = MakeEscalanteDocument(vg);
if(gd) AddManager(gd);
}
return 0;
}
bool EscalanteManager::DoRead(IStream&i, Data *data){
MakeColorList();
if(!EscalanteManager_BASE::DoRead(i,data)) return FALSE;
bool hadOne = FALSE;
Iter next(MakeIterator());
class Manager * m;
while(m = (class Manager*) next()){
hadOne = TRUE;
RemoveManager(m);
//??? Don't think I have to do this here ???
//SafeDelete(m);
}
sgraph=0; vgraphs=0;
if(data->Type() == cDocTypeSgVgs){
if(gVSetIO) ReadInVSet(i);
#ifdef USE_STRUCTURAL
if(gSSetIO) ReadInSSet(i);
#endif
i >> sgraph;
i >> vgraphs;
{
GetVGraphElementSet()->ForEach(GraphObject,InitAfterReading)();
}
#ifdef USE_STRUCTURAL
{
GetSGraphElementSet()->ForEach(GraphObject,InitAfterReading)();
}
#endif
}
else if(data->Type() == cDocTypeSgVg){
if(gVSetIO) ReadInVSet(i);
#ifdef USE_STRUCTURAL
if(gSSetIO) ReadInSSet(i);
#endif
{
GetVGraphElementSet()->ForEach(GraphObject,InitAfterReading)();
}
#ifdef USE_STRUCTURAL
{
GetSGraphElementSet()->ForEach(GraphObject,InitAfterReading)();
}
#endif
VGraphElement * tmpVg =0;
sgraph =0;
i >> sgraph;
i >> tmpVg;
vgraphs = new ObjList();
vgraphs->Add(tmpVg);
}
else if(data->Type() == cDocTypeVg){
if(gVSetIO) ReadInVSet(i);
{
GetVGraphElementSet()->ForEach(GraphObject,InitAfterReading)();
}
sgraph =0;
VGraphElement * tmpVg =0;
i >> tmpVg;
vgraphs = new ObjList();
vgraphs->Add(tmpVg);
}
else if(data->Type() == cDocTypeVgs){
if(gVSetIO) ReadInVSet(i);
i >> vgraphs;
sgraph =0;
{
GetVGraphElementSet()->ForEach(GraphObject,InitAfterReading)();
}
}
if(!vgraphs) {
if(hadOne) Show();
return FALSE;
}
Show();
return TRUE;
}
bool EscalanteManager::DoWrite(OStream&o, Data *){
Iter next(MakeIterator());
class Manager * m;
while(m = (class Manager*) next())
m->GetCmdP()->Finish();
gGraphModified = FALSE;
Modified(FALSE);
o << cMagic SP << cDocTypeSgVgs SP << gApplication->ProgramName() NL;
if(gVSetIO) WriteOutVSet(o);
#ifdef USE_STRUCTURAL
if(gSSetIO) WriteOutSSet(o);
#endif
o << sgraph SP << vgraphs SP ;
return TRUE;
}
NewMetaImpl(Escalante,Escalante_BASE, (TP(vgs), TP(sg),0));
Escalante::Escalante(int argc, char **argv) : Application(argc, argv, cDocTypeBasic){
sg = 0;
vgs = 0;
version = "\nEscalante Version 2.1 - 7/14/93, \251 Jeff McWhirter, jeffm@cs.colorado.edu";
gGridSize = Point(10,10);
gGridSize.y= Env::GetValue("EscalanteView.GridSizeY",10);
gGridSize.x= Env::GetValue("EscalanteView.GridSizeX",10);
gViewSize.x = Env::GetValue("EscalanteView.ViewSizeX",300);
gViewSize.y = Env::GetValue("EscalanteView.ViewSizeY",200);
gObsViewZoom= (float)Env::GetValue("ObserverView.ZoomFactor",40)/100;
gNoRepeatAdd= Env::GetValue("EscalanteView.NoRepeatAdd",0);
gPaletteDocumentSquare= Env::GetValue("PaletteDocument.MakeSquare",0);
gPaletteDocumentRows = Env::GetValue("PaletteDocument.PaletteRows",0);
gPaletteDocumentCols = Env::GetValue("PaletteDocument.PaletteCols",1);
gGravity = Env::GetValue("EscalanteView.Gravity",40);
gRubberBand = Env::GetValue("EscalanteView.RubberBand",1);
gNameInPalette = Env::GetValue("EscalanteView.DrawNameInPalette",1);
gBitmapInPalette = Env::GetValue("EscalanteView.DrawBitmapInPalette",1);
gPaletteGap.x = Env::GetValue("EscalanteView.PaletteGap",2);
gPaletteGap.y= Env::GetValue("EscalanteView.PaletteGap",2);
gPaletteItemSize.x = Env::GetValue("EscalanteView.PaletteItemSizeX",16);
gPaletteItemSize.y = Env::GetValue("EscalanteView.PaletteItemSizeY",16);
gMakePalette= Env::GetValue("EscalanteView.MakePalette",1);
gPaletteRows = Env::GetValue("EscalanteView.PaletteRows",0);
gPaletteCols = Env::GetValue("EscalanteView.PaletteCols",1);
gPaletteThreshold = Env::GetValue("EscalanteView.PaletteThreshold",0);
gPaletteOrientation = Env::GetValue("EscalanteView.PaletteOrientation",0);
gDoBell = Env::GetValue("EscalanteView.DoBell",0);
gTransNewGraph = Env::GetValue("EscalanteView.TransNewGraph",1);
gTransNorth = Env::GetValue("EscalanteView.TransNorth",1);
}
Command *Escalante::DoMenuCommand(int cmd){
if(cmd == cABOUT){
ShowAlert(eAlertSun,"%s %s", ProgramName(),version);
return gNoChanges;
}
return Escalante_BASE::DoMenuCommand(cmd);
}
Escalante::~Escalante(){}
bool Escalante::CanOpen(Data *data){
if(data->Type() == cDocTypeSgVgs ||
data->Type() == cDocTypeSgVg ||
data->Type() == cDocTypeVg ||
data->Type() == cDocTypeVgs) return TRUE;
else return Escalante_BASE::CanOpen(data);
}
EscalanteManager * Escalante::MakeEscalanteManager(SGraphElement * sg,ObjList * vgs)
{
return new EscalanteManager(sg,vgs);
}
Manager *Escalante::DoMakeManager(Symbol type){
sg =0;
vgs =0;
if(type == cDocTypeBasic)MakeGraph(sg,vgs);
gEscalanteManager = MakeEscalanteManager(sg,vgs);
return gEscalanteManager;
}
VObject *PaletteDocument::DoMakeContent(){
int rows = gPaletteDocumentRows;
int cols = gPaletteDocumentCols;
int orient= Env::GetValue("PaletteDocument.PaletteOrientation",0);
int dopalette = Env::GetValue("EscalanteView.DoPaletteScroller",1);
palette= new CollectionView(this, tools, eCVDefault,rows,cols);
palette->SetGap(gPaletteGap);
palette->SetId(cIdPalette);
Point min(30,30);
if(dopalette){
paletteWrapper =new Scroller(palette,min,cIdNone,(ScrollDir)(eScrollNone));
Ink * bg = gLook->GetBackgroundColor();
((Scroller*)paletteWrapper)->SetBgInk(bg);
}
else
paletteWrapper = new Clipper(palette,
min,
cIdNone,
gLook->GetBackgroundColor());
if(gPaletteDocumentSquare){
paletteWrapper->SetFlag(eVObjHFixed,TRUE);
paletteWrapper->SetFlag(eVObjVFixed,TRUE);
}
else {
if(orient == PALETTE_LEFT || orient == PALETTE_RIGHT)
paletteWrapper->SetFlag(eVObjHFixed,TRUE);
else
paletteWrapper->SetFlag(eVObjVFixed,TRUE);
}
MakeToolList();
return (VObject*)new Matte(Point(2,2),paletteWrapper);
}
PaletteDocument::PaletteDocument(EscalanteView *theview): Document(cDocTypeBasic){
Manager::SetName("Palette");
view = theview;
if(view) view->AddObserver(this);
tools = new ObjList();
palette = 0;
}
void PaletteDocument::DoObserve(int id, int part, void *d , Object *op){
if(part == cPartSenderDied && op == view) view = 0;
else if( id == cPaletteChanged && op == view){
MakeToolList();
}
else PaletteDocument_BASE::DoObserve(id, part,d , op);
}
void PaletteDocument::Control(int id, int part, void *val){
if(!view){
Document::Control(id,part,val);
return;
}
if (palette &&
id == cIdPalette &&
(part == cPartCollSelect || part == cPartCollDoubleSelect)){
Point ix= palette->GetSelection().origin;
VObject * vop = palette->GetItem(ix.x,ix.y);
if(!vop) return;
VObject* inner =0;
//
//Is this a PaletteItem with its element set?
//
if(vop->IsKindOf(Button)) {
inner = ((Button*)vop)->At(0);
if(inner && inner ->IsKindOf(PaletteItem)) {
VGraphElement * vp = ((PaletteItem*)inner)->elt;
if(vp){
view->SetTool(vp);
return;
}
}
}
//
//If not an element then call SetAction with the id of the VObject
//
view->SetAction((Actions)vop->GetId(),(void*)vop);
}
else Document::Control(id,part,val);
}
void PaletteDocument::MakeToolList(){
VGraphElement * elt;
if(!view) return;
ObjList * graphProtos = view->GetProtoList();
ObjList dummy2;
if(!graphProtos) graphProtos = &dummy2;
//
//set the palette list to this dummy so that when we are yanking and
//putting things into the tools list it doesn't affect the palette
//
ObjList dummy;
palette->SetCollection(&dummy,FALSE);
//
//Put the unused PaletteItems into the extra list so we don't have to keep
//deleting and making new
//
PaletteItem * ei;
Button * button;
VObject * tmpo;
while(tmpo = (VObject*)tools->RemoveLast())
gExtraPaletteItems.Add(tmpo);
Iter next(graphProtos);
Point maxp(20,10);
// Metric m;
while (elt= (VGraphElement*) next())
if(elt->IsKindOf(VGraphElement)){
if(elt->ShowInPalette()){
tmpo = (VObject*)gExtraPaletteItems.RemoveLast();
ei =0;
button = 0;
if(tmpo){
if(tmpo->IsKindOf(PaletteItem)) ei = (PaletteItem*)tmpo;
else if(tmpo->IsKindOf(Button)){
button =(Button*)tmpo;
ei = (PaletteItem*)((Button*)tmpo)->At(0);
if(ei && ei->IsKindOf(PaletteItem)){}
else ei=0;
}
}
if(ei)
ei->Init(elt,gPaletteItemSize);
else {
ei = new PaletteItem(elt, gPaletteItemSize);
button = (Button*)new PaletteButton(cIdNone,ei);
}
tools->Add(button);
}
}
view->AddToToolList(tools);
palette->SetCollection(tools,FALSE);
Iter next2(tools);
while(tmpo = (VObject*) next2())
maxp = Max(maxp,tmpo->GetMinSize().extent);
palette->SetMinExtent(maxp);
maxp+=gPoint1;
int rows,cols;
rows = gPaletteDocumentRows;
cols = gPaletteDocumentCols;
int size = tools->Size();
if(gPaletteDocumentSquare && size != 0){
rows =0;
cols = Math::Sqrt(size);
if(cols ==0) cols = 1;
}
palette->SetColsRows(Point(cols,rows));
if(rows !=0)
maxp.y = maxp.y*rows;
else if(cols !=0)
maxp.x = maxp.x*cols;
// Point oldmin;
// Clipper *paletteClipper=0;
// if(paletteWrapper->IsKindOf(Scroller))
// paletteClipper = ((Scroller*)paletteWrapper)->GetClipper();
// else if(paletteWrapper->IsKindOf(Clipper))
// paletteClipper = (Clipper*)paletteWrapper;
//
// if(paletteClipper){
// Window * w = GetWindow();
// if(w) w->SetExtent(paletteClipper->contentRect.extent);
// }
}